//package com.plian.system.controller.hr.abroad;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.FileTools;
//import com.plian.Tools.Func;
//import com.plian.Tools.StringPool;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.common.status.CustomCode;
//import com.plian.system.config.Resubmit;
//import com.plian.system.dto.hr.abroad.AbroadBusinessDTO;
//import com.plian.system.entity.hr.abroad.AbroadBusiness;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.search.TokenSearch;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.hr.abroad.IAbroadBusinessService;
//import com.plian.system.service.hr.abroad.IAbroadDeclarationService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.hr.abroad.AbroadBusinessVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.wrapper.hr.abroad.AbroadBusinessWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.List;
//import java.util.Optional;
//
//
///**
// * 因公出国（境）管理 控制器
// *
// * @author gangan
// * @since 2019-12-13
// */
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/abroadbusiness")
//public class AbroadBusinessController extends BaseController {
//
//	private IAbroadBusinessService abroadBusinessService;
//
//	private IAbroadDeclarationService abroadDeclarationService;
//
//	private FormWorkflowService formWorkflowService;
//
//	private IFormCodeService formCodeService;
//
//	private AbroadBusinessWrapper abroadBusinessWrapper;
//
//    /**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public R<AbroadBusinessVO> detail(@Valid @RequestBody AbroadBusiness abroadBusiness) {
//        AbroadBusiness detail = abroadBusinessService.getOne(Condition.getQueryWrapper(abroadBusiness));
//        AbroadBusinessVO abroadBusinessVO = abroadBusinessWrapper.entityToVO(detail);
//        return abroadBusinessService.getDetailObj(abroadBusinessVO);
//	}
//
//	/**
//	* 分页 因公出国（境）管理
//	*/
//	@PostMapping("/list")
//	public ListResult<AbroadBusinessVO> list(@Valid @RequestBody Query query) {
//		if(query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//		}
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<AbroadBusiness> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new AbroadBusiness()), entityList
//        );
//		TokenSearch<AbroadBusiness> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//
//		IPage<AbroadBusiness> pages = abroadBusinessService.page(Condition.getPage(query), queryWrapper);
//        List<AbroadBusinessVO> abroadBusinessVOS = abroadBusinessWrapper.entityToVO(pages.getRecords());
//		ListResult<AbroadBusinessVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(abroadBusinessVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//
//
//	/**
//	* 新增或修改 因公出国（境）管理
//	*/
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public R submit(@Valid @RequestBody AbroadBusinessVO abroadBusinessVO) {
//        AbroadBusiness abroadBusiness = new AbroadBusiness();
//        BeanUtils.copyProperties(abroadBusinessVO, abroadBusiness);
//        //子表校验
//		String checkResult = abroadBusinessService.checkChild(abroadBusinessVO);
//		if(!"success".equals(checkResult)){
//			return new R(CustomCode.builder().message(checkResult).code(1999).success(false).build());
//		}
//		Boolean result = abroadBusinessService.submit(abroadBusinessVO);
//
//		return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//
//	/**
//	* 删除 因公出国（境）管理
//	*/
//	@PostMapping("/remove")
//	public R remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>)pd.get("ids");
//		return abroadBusinessService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//	}
//
//	@PostMapping("/report")
//	public ObjResult reportTable(@Valid @RequestBody AbroadBusinessDTO abroadBusinessDTO) {
//        ObjResult objResult;
//        try {
//            ReportReturnVO reportReturnVO = abroadBusinessService.report(abroadBusinessDTO);
//            objResult = new ObjResult(CommonCode.SUCCESS);
//            if (Optional.ofNullable(reportReturnVO).isPresent()){
//                PageData pd = new PageData();
//                pd.put("grids", reportReturnVO.getGrids());
//                objResult.setPageData(pd);
//            }
//        }catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            objResult = new ObjResult(CommonCode.ERROR);
//            return objResult;
//        }
//
//        return objResult;
//	}
//
//	/**
//	 * 打印
//	 */
//	@GetMapping("/buildpdf/{id}")
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//		return FileTools.exportPdf(abroadBusinessService.createReceptFile(id));
//	}
//}
